// Command text is a chromedp example demonstrating how to extract text from a
// specific element.
package main

import (
	"context"
	"log"
	"os"
	"strconv"
	"strings"
	"time"

	"github.com/chromedp/chromedp"
)

func main() {
	var filename string
	filename = "test"
	// response, err := http.Get("https://codeforces.com/problemset/problem/1658/A")
	// if err != nil {
	// 	//...
	// 	fmt.Println(err)
	// }
	// defer response.Body.Close() //在回复后必须关闭回复的主体
	// body, err := ioutil.ReadAll(response.Body)
	// if err == nil {
	// 	fmt.Println(string(body))
	// }
	dirName := strconv.FormatInt(time.Now().Unix(), 10)
	println(dirName)
	os.Mkdir(dirName, os.ModePerm)
	getTitle(&filename)
	println(filename[3:])

}
func getTitle(res *string) {
	// create context
	ctx, cancel := chromedp.NewContext(context.Background())
	defer cancel()
	// println(res)
	// run task list
	// var res string
	err := chromedp.Run(ctx,
		chromedp.Navigate(`https://codeforces.com/problemset/problem/1658/A`),
		chromedp.Text(`.problem-statement .header .title`, res, chromedp.NodeVisible),
		// 	chromedp.Navigate(`https://pkg.go.dev/time`),
		// chromedp.Text(`.Documentation-overview`, &res, chromedp.NodeVisible),
	)
	if err != nil {
		log.Fatal(err)
	}
	// *filename = res
	log.Println(strings.TrimSpace(*res))
}
